package cn.xuanxuanyuhua.crm.web.controller;


import cn.xuanxuanyuhua.crm.domain.Role;
import cn.xuanxuanyuhua.crm.query.QueryObject;
import cn.xuanxuanyuhua.crm.service.IPermissionService;
import cn.xuanxuanyuhua.crm.service.IRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/role")
public class RoleController {

    @Autowired
    private IRoleService service;
    @Autowired
    private IPermissionService pService;

    @RequestMapping("/list")
    public String list(Model m, QueryObject qo) {
        m.addAttribute("pageInfo", service.query(qo));
        return "/role/list";
    }

    @RequestMapping("/input")
    public String input(Model m, Long id) {
        if (id != null) {
            m.addAttribute("entity", service.get(id));
        }
        m.addAttribute("permissions",pService.list());
        return "/role/input";
    }

    @RequestMapping("/saveOrUpdate")
    public String saveOrUpdate(Role entity, Long[] ids) {
        service.saveOrUpdate(entity, ids);
        return "redirect:/role/list.do";
    }

    @RequestMapping("/delete")
    public String delete(Long id) {
        service.delete(id);
        return "redirect:/role/list.do";
    }

}
